package com.wu.base;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.UUID;

/**
 * @author wuyanshen
 * @date 2019-01-23 11:20 AM
 * @discription 基础实体类,定义了id的生成方法
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public abstract class BaseEntity<T>  implements Serializable {

    private String id;

    /**
     * 获取id值(通过uuid生成唯一值)
     */
    private String uuid() {
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        return uuid;
    }

    /**
     * 插入前手动调用生成id
     */
    public void preInsert() {
        this.setId(uuid());
    }
}
